<?php
/**
 * Created by PhpStorm.
 * User: Duck
 * Create time: 2016/12/21 9:56
 */

namespace D\Controller;
use Common\Controller\BaseController;

class DictController extends BaseController{
    public function show(){
        $pages = ceil(M('dict')->count()/4);
        $a=M('dict')-> page(I('get.p'),4)->select();
        $c=M('dict')->select();
        $this->assign('navs',$a);
        $this->assign('addnavs',$c);
        $this->assign('pages',$pages);
        $this->display();
    }
    public function getShow(){
        $pages = ceil(M('dict')->count()/4);
        $res=M('dict')
            ->page(I('get.p'),4)
            ->select();
        $this->ajaxReturn($res);
    }
    public function doDelDict(){
        M('dict')->delete(I('post.ids'));
        $res = [
            'msg'=>'删除成功',
            'error'=>0
        ];
        $this->ajaxReturn($res);
    }
    public function doEditDict(){
        if(D('dict')->create()){
            D('dict') ->save();
            $res = [
            'msg'=>'修改成功',
            'error'=>0
        ];
        }else{
            $res = [
                'msg'=>D('dict')->getError(),
                'error'=>1,
            ];
        }
        $this->ajaxReturn($res);
    }
    public function doAddDict(){
        if(D('dict')->create()){
            D('dict') ->add();
            $res = [
                'msg'=>'添加成功',
                'error'=>0
            ];
        }else{
            $res = [
                'msg'=>D('dict')->getError(),
                'error'=>1,
            ];
        }
        $this->ajaxReturn($res);
    }
}